"""
反刍思维量表（Ruminative Response Scale, RRS）是一种用于评估个体在面对负面情绪时的反刍思维倾向的量表。
反刍思维量表（RRS）包含22个条目，分为三个维度：症状反刍、强迫思考和反省深思。每个条目的得分范围是1到4分，总分范围是22到88分。
症状反刍包括1,2，3,4,6,8,9,14,17,18,19,22题
强迫思考包括5,10,13,15,16题
反省深思包括7，11,12,20,21题
量表共22个条目， 3个维度。总分22~88分，“从不” 计 １ 分， “偶尔”计 ２ 分，“有时”计 ３ 分，“总是”计 ４ 分。得分越高表明反刍思维倾向越严重。
"""
class RRS:
    def __init__(self, answers):
        self.answers = answers
        self.total_score = 0
        self.symptom_rumination_score = 0
        self.intrusive_rumination_score = 0
        self.reflective_pondering_score = 0

    def calculate_scores(self):
        self._calculate_symptom_rumination()
        self._calculate_intrusive_rumination()
        self._calculate_reflective_pondering()
        self._calculate_total_score()

    def _calculate_symptom_rumination(self):
        symptom_rumination_questions = [1, 2, 3, 4, 6, 8, 9, 14, 17, 18, 19, 22]
        self.symptom_rumination_score = sum(int(self.answers[f'q{i}']) for i in symptom_rumination_questions)

    def _calculate_intrusive_rumination(self):
        intrusive_rumination_questions = [5, 10, 13, 15, 16]
        self.intrusive_rumination_score = sum(int(self.answers[f'q{i}']) for i in intrusive_rumination_questions)

    def _calculate_reflective_pondering(self):
        reflective_pondering_questions = [7, 11, 12, 20, 21]
        self.reflective_pondering_score = sum(int(self.answers[f'q{i}']) for i in reflective_pondering_questions)

    def _calculate_total_score(self):
        self.total_score = self.symptom_rumination_score + self.intrusive_rumination_score + self.reflective_pondering_score

    def get_scores(self):
        return {
            'total_score': self.total_score,
            'symptom_rumination_score': self.symptom_rumination_score,
            'intrusive_rumination_score': self.intrusive_rumination_score,
            'reflective_pondering_score': self.reflective_pondering_score
        }

# # 示例使用
# answers = {
#     'q1': '3', 'q2': '2', 'q3': '1', 'q4': '0', 'q5': '2', 'q6': '1', 'q7': '3', 'q8': '2', 'q9': '1', 'q10': '0',
#     'q11': '3', 'q12': '2', 'q13': '1', 'q14': '0', 'q15': '2', 'q16': '1', 'q17': '3', 'q18': '2', 'q19': '1', 'q20': '0',
#     'q21': '3', 'q22': '2'
# }
#
# rrs = RRS(answers)
# rrs.calculate_scores()
# scores = rrs.get_scores()
# print("Total Score:", scores['total_score'])
# print("Symptom Rumination Score:", scores['symptom_rumination_score'])
# print("Intrusive Rumination Score:", scores['intrusive_rumination_score'])
# print("Reflective Pondering Score:", scores['reflective_pondering_score'])